package com.qkm.xinguan.controller;

import com.qkm.xinguan.domain.transform.dto.HouseInfoDTO;
import com.qkm.xinguan.domain.transform.error.HouseErrorInfo;
import com.qkm.xinguan.domain.transform.form.HouseInfoSearchForm;
import com.qkm.xinguan.response.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.BindingResult;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.io.IOException;

/**
 * @author zfj
 * @date 2021/12/1 -15:28
 */
@RequestMapping("/business/houseInfo")
@Api(value = "房屋信息管理模块", tags = "房屋信息管理接口")
public interface IHouseInfoController {

	@GetMapping("/all")
	@ApiOperation(value = "分页获取房屋列表信息", notes = "分页")
	Result getAllListPage(@RequestParam(required = false, value = "page", defaultValue = "1") Integer page,
	                            @RequestParam(required = false, value = "size", defaultValue = "100") Integer size);

	@GetMapping("/list")
	@PreAuthorize("hasAuthority('houseInfo:query')")
	@ApiOperation(value = "分页获取房屋列表信息", notes = "分页")
	Result getHouseInfoListPage(@RequestParam(value = "page", defaultValue = "1") Integer page,
	                         @RequestParam(value = "size", defaultValue = "5") Integer size);

	@PostMapping("/search")
	@PreAuthorize("hasAuthority('houseInfo:query')")
	@ApiOperation(value = "查询房屋列表信息", notes = "分页查询")
	Result searchHouseInfoListPage(@RequestBody HouseInfoSearchForm searchForm, @RequestParam(value = "page", defaultValue = "1") Integer page,
	                               @RequestParam(value = "size", defaultValue = "5") Integer size);

	@PostMapping("/add")
	@PreAuthorize("hasAuthority('houseInfo:add')")
	@ApiOperation(value = "添加房屋信息", notes = "房屋信息添加")
	Result addHouseInfo(@RequestBody @Validated HouseInfoDTO houseInfoDTO, BindingResult result) throws IOException;

	@DeleteMapping("/delete/{id}")
	@PreAuthorize("hasAuthority('houseInfo:delete')")
	@ApiOperation(value = "删除房屋", notes = "房屋信息删除")
	Result deleteHouseInfo(@PathVariable("id") Long id);

	@GetMapping("/only/{id}")
	@ApiOperation(value = "获取单个房屋", notes = "根据房屋id查询房屋信息")
	Result getOnlyById(@PathVariable("id") Long id);

	@GetMapping("/{id}")
	@PreAuthorize("hasAuthority('houseInfo:queryOne')")
	@ApiOperation(value = "获取单个房屋", notes = "根据房屋id查询房屋信息")
	Result getOneById(@PathVariable("id") Long id);

	@PutMapping("/edit/{id}")
	@PreAuthorize("hasAuthority('houseInfo:update')")
	@ApiOperation(value = "编辑房屋", notes = "房屋信息修改")
	Result editHouseInfo(@RequestBody @Validated HouseInfoDTO houseInfoDTO, @PathVariable("id") Long id, BindingResult result) throws IOException;

	@PostMapping("/examineSuccess/{id}")
	@PreAuthorize("hasAuthority('houseInfo:examine')")
	@ApiOperation(value = "房屋审核通过", notes = "审核通过")
	Result updateHouseInfoStatusToPassById( @PathVariable("id") Long id);

	@PostMapping("/examineFail/{id}")
	@PreAuthorize("hasAuthority('houseInfo:examine')")
	@ApiOperation(value = "房屋审核不通过", notes = "审核不通过")
	Result updateHouseInfoStatusToFailById(@RequestBody @Validated HouseErrorInfo houseErrorInfo, @PathVariable("id") Long id, BindingResult result) throws IOException;

	@PostMapping("/lease/{id}")
	@ApiOperation(value = "房屋出租通过", notes = "出租通过")
	Result leaseHouseInfoById( @PathVariable("id") Long id) throws IOException;

	@GetMapping("/listById")
	@PreAuthorize("hasAuthority('houseInfo:list')")
	@ApiOperation(value = "根据UserId查询房屋", notes = "根据UserId查询房屋")
	Result selectHouseInfoByUserId(@RequestParam(value = "page", defaultValue = "1") Integer page,
	                               @RequestParam(value = "size", defaultValue = "5") Integer size);

	@GetMapping("/search/{keyword}")
	@ApiOperation(value = "前端es查询房屋", notes = "前端es查询房屋")
	Result searchPage(@PathVariable("keyword")String keyword) throws IOException;

	@GetMapping("/searchhouse/{keyword}")
	@ApiOperation(value = "前端es根据hs查询房屋", notes = "前端es查询房屋")
	Result searchHouse(@PathVariable("keyword")String keyword) throws IOException;

	@GetMapping("/searchdecorate/{keyword}")
	@ApiOperation(value = "前端es根据de查询房屋", notes = "前端es查询房屋")
	Result searchDecorate(@PathVariable("keyword")String keyword) throws IOException;

	@GetMapping("/random")
	@ApiOperation(value = "随机查询4个", notes = "随机查询4个")
	Result randomFour();
}
